/// 用户信息模型 - User Info Model
/// 
/// 根据后端JSON数据结构定义，用于数据转换
/// Defined based on backend JSON data structure for data conversion
class UserInfo {
  final String? id;
  final String? username;
  final String? email;
  final String? avatar;
  final String? nickname;
  final String? phone;
  final String? gender;
  final DateTime? birthday;
  final String? location;
  final String? bio;
  final bool? isVip;
  final DateTime? vipExpireDate;
  final int? points;
  final int? level;
  final DateTime? createdAt;
  final DateTime? updatedAt;

  const UserInfo({
    this.id,
    this.username,
    this.email,
    this.avatar,
    this.nickname,
    this.phone,
    this.gender,
    this.birthday,
    this.location,
    this.bio,
    this.isVip,
    this.vipExpireDate,
    this.points,
    this.level,
    this.createdAt,
    this.updatedAt,
  });

  /// 从JSON创建模型 - Create model from JSON
  factory UserInfo.fromJson(Map<String, dynamic> json) {
    return UserInfo(
      id: json['id']?.toString(),
      username: json['username']?.toString(),
      email: json['email']?.toString(),
      avatar: json['avatar']?.toString(),
      nickname: json['nickname']?.toString(),
      phone: json['phone']?.toString(),
      gender: json['gender']?.toString(),
      birthday: json['birthday'] != null 
          ? DateTime.tryParse(json['birthday'].toString())
          : null,
      location: json['location']?.toString(),
      bio: json['bio']?.toString(),
      isVip: json['isVip'],
      vipExpireDate: json['vipExpireDate'] != null 
          ? DateTime.tryParse(json['vipExpireDate'].toString())
          : null,
      points: json['points']?.toInt(),
      level: json['level']?.toInt(),
      createdAt: json['createdAt'] != null 
          ? DateTime.tryParse(json['createdAt'].toString())
          : null,
      updatedAt: json['updatedAt'] != null 
          ? DateTime.tryParse(json['updatedAt'].toString())
          : null,
    );
  }

  /// 转换为JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'username': username,
      'email': email,
      'avatar': avatar,
      'nickname': nickname,
      'phone': phone,
      'gender': gender,
      'birthday': birthday?.toIso8601String(),
      'location': location,
      'bio': bio,
      'isVip': isVip,
      'vipExpireDate': vipExpireDate?.toIso8601String(),
      'points': points,
      'level': level,
      'createdAt': createdAt?.toIso8601String(),
      'updatedAt': updatedAt?.toIso8601String(),
    };
  }
}